// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial

export global Glob {
    in-out property <[string]> model: ["Hello", "World"];
    in-out property <bool> condition: true;
    callback clicked(string);
    clicked => {
        model = ["oops"];
    }
    in-out property <string> value;
}

component Button {
    callback clicked();
    in property <string> text;
    Rectangle {
        background: yellow;
        Text { text: text; }
        TouchArea {
            clicked => {clicked();}
        }
    }
}


component TestCase inherits Window {
    width: 300px;
    height: 300px;
    VerticalLayout {
        for string in Glob.model: Rectangle {
            if Glob.condition: Button {
                text: string;
                width: 80%;
                height: 80%;
                clicked => {
                    Glob.value = string;
                    Glob.clicked(string);
                    //Glob.value = string; // FIXME: this still crashes (#3464)
                }
            }
        }
        Rectangle {}
    }
}

/*
```rust
let instance = TestCase::new().unwrap();
let model = std::rc::Rc::new(slint::VecModel::<slint::SharedString>::from(
    vec!["hello".into(), "world".into()]));
instance.global::<Glob<'_>>().set_model(model.clone().into());
instance.global::<Glob<'_>>().on_clicked(move |val|{
    assert_eq!(val, "world");
    model.remove(1);
});
slint_testing::send_mouse_click(&instance, 150., 150.);
assert_eq!(instance.global::<Glob<'_>>().get_value(), "world");
```

```cpp
auto handle = TestCase::create();
TestCase &instance = *handle;

std::vector<slint::SharedString> array;
array.push_back("hello");
array.push_back("world");
auto model = std::make_shared<slint::VectorModel<slint::SharedString>>(std::move(array));
instance.global<Glob>().set_model(model);
instance.global<Glob>().on_clicked([=](slint::SharedString val){
    assert_eq(val, "world");
    model->erase(1);
});
slint_testing::send_mouse_click(&instance, 150., 150.);
assert_eq(instance.global<Glob>().get_value(), "world");
```


```js
var instance = new slint.TestCase({});
let model = new slintlib.ArrayModel(["hello", "world"]);
instance.Glob.model = model;
instance.Glob.clicked = (val) => {
    assert.equal(val, "world");
    model.remove(1, 1);
};
slintlib.private_api.send_mouse_click(instance, 150., 150.);
assert.equal(instance.Glob.value, "world");
```


*/
